home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 41
/
Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso
/
-seriously_amiga-
/
graphics
/
picsize
/
picsize.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-04-19
|
3KB
|
123 lines
/* :ts=3
** determines picture information using datatypes
**
** written & © Ralph Reuchlein 1999
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <datatypes/pictureclass.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/datatypes.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#define TEMPLATE "PICTURE=PIC/A,"\
"WIDTH/S,"\
"HEIGHT/S,"\
"SIZE/S,"\
"DEPTH/S,"\
"FORMAT/S,"\
"FULL/S"
enum
{
OPT_PIC,
OPT_WIDTH,
OPT_HEIGHT,
OPT_SIZE,
OPT_DEPTH,
OPT_FORMAT,
OPT_FULL,
OPT_COUNT
};
#define OPTS_PIC (STRPTR)opts[OPT_PIC]
#define OPTS_WIDTH (opts[OPT_WIDTH]==-1)
#define OPTS_HEIGHT (opts[OPT_HEIGHT]==-1)
#define OPTS_SIZE (opts[OPT_SIZE]==-1)
#define OPTS_DEPTH (opts[OPT_DEPTH]==-1)
#define OPTS_FORMAT (opts[OPT_FORMAT]==-1)
#define OPTS_FULL (opts[OPT_FULL]==-1)
void error(STRPTR,...);
STRPTR basename(STRPTR);
void main(UWORD argc, STRPTR argv[])
{
static long opts[OPT_COUNT];
struct RDArgs *rdargs;
Object *picobj;
struct BitMapHeader *bmhdr;
struct DataType *dt;
/* parse parameters */
if(rdargs = ReadArgs(TEMPLATE, opts, NULL))
{
if (picobj=NewDTObject(OPTS_PIC,PDTA_FreeSourceBitMap,TRUE,TAG_DONE))
{
GetDTAttrs(picobj,PDTA_BitMapHeader,&bmhdr,DTA_DataType,&dt,TAG_DONE);
while(TRUE)
{
if (OPTS_WIDTH && OPTS_HEIGHT)
{
printf("%ux%u\n",bmhdr->bmh_Width,bmhdr->bmh_Height); break;
}
if (OPTS_WIDTH) { printf("%u\n",bmhdr->bmh_Width); break;}
if (OPTS_HEIGHT) { printf("%u\n",bmhdr->bmh_Height); break;}
if (OPTS_SIZE) { printf("%ux%ux%u\n",bmhdr->bmh_Width,bmhdr->bmh_Height,bmhdr->bmh_Depth); break;}
if (OPTS_DEPTH) { printf("%u\n",bmhdr->bmh_Depth); break;}
if (OPTS_FORMAT) { printf("%.99s\n",dt->dtn_Header->dth_Name); break;}
printf("%-30s\t%ux%ux%u, %.99s\n",basename(OPTS_PIC),bmhdr->bmh_Width,bmhdr->bmh_Height,bmhdr->bmh_Depth,dt->dtn_Header->dth_Name);
break;
}
DisposeDTObject(picobj);
}
else
{
error("Couldn't generate new datatype object from '%s'!",OPTS_PIC);
}
FreeArgs(rdargs);
}
else
{
error("Usage:\n%s %s",argv[0],TEMPLATE);
}
}
void error(STRPTR fmt,...)
{
va_list args;
va_start(args,fmt);
vfprintf(stderr,fmt,args);
vfprintf(stderr,"\n",NULL);
va_end(args);
}
STRPTR basename(STRPTR fullname)
{
register WORD i;
for (i=(strlen(fullname)-1);i>=0;i--)
{
if (fullname[i]=='/') return(&fullname[i+1]);
if (fullname[i]==':') return(&fullname[i+1]);
}
return(fullname);
}